﻿using lib472.Model.Frm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace lib472.API
{
    public  class Clientbuss
    {
        public static string ApiUrl = "http://localhost:5218";

        //public const string ApiUrl = "http://localhost:5100";

        public static string Post(string Url, object Args)
        {


            HttpModel httpModel = Client.Post($"{ApiUrl}/api{Url}", Args);
            if (!httpModel.IsSuccessStatusCode)
            {
                //MessageBox.Show($"錯誤:{httpModel.content}", "服務器錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new HttpRequestException($"{ httpModel.content}");
            }
            if (httpModel.content == null)
            {
                return string.Empty;
            }
            return httpModel.content;



        }


        public static string Get(string Url, Dictionary<string, string> Args)
        {

            HttpModel httpModel = Client.Get($"{ApiUrl}/api{Url}", Args);
            if (!httpModel.IsSuccessStatusCode)
            {
                //MessageBox.Show($"錯誤:{httpModel.content}", "服務器錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Config.Errorlog.Error($"API錯誤\r\n URL:{ApiUrl}{Url}\r\n錯誤:{httpModel.httpStatusCode}");
                throw new HttpRequestException($"{httpModel.content}");
            }
            if (httpModel.content == null)
            {
                return string.Empty;
            }
            return httpModel.content;
        }
    }
}
